<?php
App::uses('AppModel', 'Model');
/**
 * Configuration Model
 *
 * @property Domain $Domain
 * @property Upload $Upload
 */
class Configuration extends AppModel {
/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'name';
/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'domain_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'name' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'value' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'Domain' => array(
			'className' => 'Domain',
			'foreignKey' => 'domain_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Upload' => array(
			'className' => 'Upload',
			'foreignKey' => 'upload_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
	
	
	public function install($id = null){
		
		$count = $this->find('count',array('conditions'=>array('Configuration.domain_id'=>$id)));
		
		if(!is_null($id) && !empty($id)){
			
			$querys = array(
				'homepage_name'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'homepage_name','',1);",
				'homepage_title'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'homepage_title','',1);",
				'homepage_keywords'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'homepage_keywords','',1)",
				'homepage_description'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'homepage_description','',1)",
				'baner_1_url'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'baner_1_url','',2)",
				'baner_2_url'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'baner_2_url','',2)",
				'baner_3_url'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'baner_3_url','',2)",
				'baner_4_url'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'baner_4_url','',2)",
				'baner_5_url'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'baner_5_url','',2)",
				'baner_6_url'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'baner_6_url','',2)",
				'baner_7_url'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'baner_7_url','',2)",
				'twitterId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'twitterId','designchemical',3)",
				'facebookId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'facebookId','157969574262873',3)",
				'fblikeId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'fblikeId','157969574262873',3)",
				'fbrecId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'fbrecId','http://www.designchemical.com',3)",
				'googleId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'googleId','111470071138275408587',3)",
				'linkedinId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'linkedinId','589883,http://www.linkedin.com/in/leechestnutt',3)",
				'rssId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'rssId','http://feeds.feedburner.com/DesignChemical',3)",
				'flickrId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'flickrId','null',3)",
				'deliciousId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'deliciousId','designchemical',3)",
				'youtubeId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'youtubeId','wired',3)",
				'diggId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'diggId','remix4',3)",
				'pinterestId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'pinterestId','designchemical',3)",
				'lastfmId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'lastfmId','lastfm',3)",
				'dribbbleId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'dribbbleId','frogandcode',3)",
				'vimeoId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'vimeoId','brad',3)",
				'stumbleuponId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'stumbleuponId','remix4',3)",
				'tumblrId'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'tumblrId','null',3)",
				'GoogleSearchForm'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'GoogleSearchForm','null',4)",
				'GoogleSearchResults'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'GoogleSearchResults','null',4)",
				'GoogleAnalyticsScript'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'GoogleAnalyticsScript','null',4)",
				'CustomMetaTags'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'CustomMetaTags','null',6)",
				'copyright'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'copyright','Copyright &copy by SEO Solution',7)",
				'footerContent'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'footerContent','null',7)",
				'logo'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'logo','',8)",
				'main_background'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'main_background','',8)",
				'text_background'=>"INSERT INTO `configurations` VALUES (NULL,{$id},NULL,'text_background','',8)",
				'homepage_display_categories'=>"INSERT INTO `configurations` VALUES (NULL,{$id},1,'homepage_display_categories','',9)",
				'homepage_display_ratings'=>"INSERT INTO `configurations` VALUES (NULL,{$id},1,'homepage_display_ratings','',9)",
				'homepage_display_posts'=>"INSERT INTO `configurations` VALUES (NULL,{$id},1,'homepage_display_posts','',9)",
				'homepage_display_articles'=>"INSERT INTO `configurations` VALUES (NULL,{$id},1,'homepage_display_articles','',9)"
			);
			
			foreach ($querys as $key => $query) {
				$isset = $this->find('count',array('conditions'=>array('Configuration.domain_id'=>$id,'Configuration.name'=>$key)));
				if($isset == 0) $this->query($query);
			}
			return true;
						
		}else{
			return false;
		}
	}
	
// 	public function afterSave( $options = array() ) {
// 		if(isset($this->data['Configuration']['domain_id'])){
// 			$this->Domain->id = $this->data['Configuration']['domain_id'];
// 			$this->Domain->saveField('cache',1);
// 		}
// 		return true;
// 	}
	
}
